package com.skywolf.chem.usercenter.controller;


import com.skywolf.chem.common.sysconfig.response.RespData;
import com.skywolf.chem.usercenter.pojo.param.RolePermissionParam;
import com.skywolf.chem.usercenter.pojo.vo.PermissionVO;
import com.skywolf.chem.usercenter.service.IRolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色和权限关系表 前端控制器
 * </p>
 *
 * @author
 * @since 2019-12-02
 */
@RestController
@RequestMapping("/usercenter/role-permission")
@Api(value = "管理后台角色权限API", description = "管理后台角色权限API")
public class RolePermissionController {

    @Autowired
    private IRolePermissionService rolePermissionService;

    /**
     * 保存角色权限
     *
     * @param rolePermissionParam 角色权限参数
     * @return
     */
    @ApiOperation(value = "保存角色权限")
    @PostMapping
    public RespData saveRolePermission(@RequestBody @Validated RolePermissionParam rolePermissionParam) {
        rolePermissionService.saveRolePermission(rolePermissionParam);
        return RespData.success();
    }

    /**
     * 获取角色的权限
     *
     * @param roleId
     * @return
     */
    @ApiOperation(value = "获取角色权限")
    @GetMapping("/{roleId}")
    public RespData<List<PermissionVO>> listRolePermission(@PathVariable String roleId) {
        List<PermissionVO> permissionVOList = rolePermissionService.listRolePermission(roleId);
        return RespData.success(permissionVOList);
    }

}
